/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.systemView;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.SwingUtilities;

import com.ruipengkj.ApplicationContext;
import com.ruipengkj.commons.util.SwingUtil;
import com.ruipengkj.commons.util.Util;
import com.ruipengkj.view.base.BaseInternalFrame;

/**
 * 说明：
 * 会员主窗体
 * @Author：李智深
 * @Date：2012-03-15
 * 
 */
public class SystemInternalFrame extends BaseInternalFrame{

	private static final long serialVersionUID = 1L;
	
	private JToolBar toolBar;//工具栏
	
	private JPanel main;//主面板
	private CardLayout main_layout;//主面板布局
	private JButton systemOperationLogButton;//操作日志管理按钮
	private JButton systemRolePermissionsButton;//角色权限管理按钮
	private JButton systemSetAllocationButton;//系统配置设置按钮
	private JButton systemBarcodeButton;//条码生成管理按钮
	private JButton systemBackupReductionButton;//数据库备份还原按钮
	private JButton paramDisplayButton;//客显测试
	
	private SystemManageLog systemManageLog;//操作日志管理面板
	private SystemManagePrivilege systemManagePrivilege;//角色管理面板
	private SystemSetAllocation systemSetAllocation;//系统配置设置面板
	private SystemManageBarCode systemManageBarCode;//条形码生成管理面板
	private SystemBackupReduction SystemBackupReduction;//数据库备份还原面板
	private ParamDisplayPanel paramDisplayPanel;//客显测试
	public SystemInternalFrame(String title, boolean resizable, boolean closable, boolean maximizable,boolean iconifiable){
		super(title, resizable, closable, maximizable,iconifiable);
		this.init();
	}
	
	private void init(){
		this.setLayout(new BorderLayout());
		this.initViews();
		this.initListener();
	}
	
	//初始化组件
	private void initViews(){
		toolBar = new JToolBar();
		toolBar.setFloatable(false);//设置工具栏不可移动
		systemOperationLogButton=new JButton("操作日志管理",SwingUtil.getOpenSwingImage("operat_log_manager.png"));
		systemRolePermissionsButton=new JButton("角色权限管理",SwingUtil.getOpenSwingImage("role_purview_manager.png"));
		systemSetAllocationButton=new JButton("系统配置设置",SwingUtil.getOpenSwingImage("system_deploy_setting.png"));
		systemBarcodeButton=new JButton("条码生成管理",SwingUtil.getOpenSwingImage("barcode_generate_manager.png"));
		systemBackupReductionButton = new JButton("数据库备份还原",SwingUtil.getOpenSwingImage("database_process.png"));
		paramDisplayButton= new JButton("客显测试",SwingUtil.getOpenSwingImage("database_process.png"));
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL81)){
			toolBar.add(systemOperationLogButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL82)){
			toolBar.add(systemRolePermissionsButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL83)){
			toolBar.add(systemSetAllocationButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL84)){
			toolBar.add(systemBarcodeButton);
		}
		if(ApplicationContext.TRIGHT_LIST.contains(ApplicationContext.RIGHT_LIVEL85)){
			toolBar.add(systemBackupReductionButton);
		}
//		toolBar.add(paramDisplayButton);
		main=new JPanel();
		main_layout=new CardLayout();
		main.setLayout(main_layout);
		
		this.add(toolBar,BorderLayout.NORTH);
		this.add(main,BorderLayout.CENTER);
	}
	
	//初始化监听器
	private void initListener(){
		systemOperationLogButton.addActionListener(this);
		systemRolePermissionsButton.addActionListener(this);
		systemSetAllocationButton.addActionListener(this);
		systemBarcodeButton.addActionListener(this);
		systemBackupReductionButton.addActionListener(this);
		paramDisplayButton.addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==systemOperationLogButton){
			//操作日志管理按钮
			systemManageLog = new SystemManageLog();
			main.add(systemManageLog, "systemManageLog");
			main_layout.show(main, "systemManageLog");
			this.setTitle("系统设置--操作日志管理");
			Util.setButtonStatus(toolBar,systemOperationLogButton);
			SwingUtilities.invokeLater(systemManageLog);
		}else if(e.getSource()==systemRolePermissionsButton){
			//角色权限管理按钮
			systemManagePrivilege = new SystemManagePrivilege();
			main.add(systemManagePrivilege, "systemManagePrivilege");
			main_layout.show(main, "systemManagePrivilege");
			this.setTitle("系统设置--角色权限管理");
			Util.setButtonStatus(toolBar,systemRolePermissionsButton);
			SwingUtilities.invokeLater(systemManagePrivilege);
		}else if(e.getSource()==systemSetAllocationButton){
			//系统配置设置按钮
			systemSetAllocation = new SystemSetAllocation();
			main.add(systemSetAllocation, "SystemSetAllocation");
			main_layout.show(main, "SystemSetAllocation");
			this.setTitle("系统设置--系统配置设置");
			Util.setButtonStatus(toolBar,systemSetAllocationButton);
			SwingUtilities.invokeLater(systemSetAllocation);
		}else if(e.getSource()==systemBarcodeButton){
			//条码生成管理按钮
			systemManageBarCode = new SystemManageBarCode();
			main.add(systemManageBarCode, "systemManageBarCode");
			main_layout.show(main, "systemManageBarCode");
			this.setTitle("系统设置--条码生成");
			Util.setButtonStatus(toolBar,systemBarcodeButton);
			SwingUtilities.invokeLater(systemManageBarCode);
		} else if (e.getSource() == systemBackupReductionButton) {
			//数据库备份还原
			SystemBackupReduction = new SystemBackupReduction();
			main.add(SystemBackupReduction, "SystemBackupReduction");
			main_layout.show(main, "SystemBackupReduction");
			this.setTitle("系统设置--数据库备份还原");
			Util.setButtonStatus(toolBar,systemBackupReductionButton);
		}else if(e.getSource()==paramDisplayButton){
			//客显测试
			paramDisplayPanel = new ParamDisplayPanel();
			main.add(paramDisplayPanel, "paramDisplayPanel");
			main_layout.show(main, "paramDisplayPanel");
			Util.setButtonStatus(toolBar,paramDisplayButton);
		}
		main.updateUI();
	}
	public void showButton(){
		if (toolBar != null && toolBar.getComponentCount() != 0)
			((JButton)toolBar.getComponent(0)).doClick();
	}
	
	public void showButton(int type){
		switch(type){
			case 1:{systemOperationLogButton.doClick();break;}
			case 2:{systemRolePermissionsButton.doClick();break;}
			case 3:{systemSetAllocationButton.doClick();break;}
			case 4:{systemBarcodeButton.doClick();break;}
			case 5:{systemBackupReductionButton.doClick();break;}
		}
	}
}
